package cn.edu.imust.loginregisterdemo.register.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.Bmob;
import cn.edu.imust.loginregisterdemo.R;
import cn.edu.imust.loginregisterdemo.base.BaseFragment;
import cn.edu.imust.loginregisterdemo.login.view.LoginActivity;

public class RegisterActivity extends AppCompatActivity {


    private SmsRegisterFragment      smsRegisterFragment;
    private UsernameRegisterFragment usernameRegisterFragment;
    private FragmentManager          fm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
        Bmob.initialize(this, "33452dfaa0b4f1b9b1a5ea2c1818d5f4");
        usernameRegisterFragment = new UsernameRegisterFragment();
        smsRegisterFragment = new SmsRegisterFragment();
        fm = getSupportFragmentManager();
        switchFragment(smsRegisterFragment);

    }

    private void switchFragment(BaseFragment targetFragment) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.register_page_container, targetFragment);
        ft.commit();

    }

    @OnClick({R.id.iv_login_return, R.id.to_username_register, R.id.to_sms_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_login_return:
                startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
                finish();
                break;
            case R.id.to_username_register:
                switchFragment(usernameRegisterFragment);
                break;
            case R.id.to_sms_register:
                switchFragment(smsRegisterFragment);
                break;
        }
    }


}
